package com.naiterui.ehp.bs.cms.modules.notice.controller;

import javax.validation.constraints.NotNull;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.naiterui.ehp.bp.bo.notice.NoticeMessageBO;
import com.naiterui.ehp.bp.constants.SwaggerTag;
import com.naiterui.ehp.bp.security.annotation.SysLog;
import com.naiterui.ehp.bs.cms.common.vo.PageParamsVO;
import com.naiterui.ehp.bs.cms.common.vo.PageVO;
import com.naiterui.ehp.bs.cms.modules.notice.service.NoticeMessageService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;

/**
 * @author luao
 * @date 2021/3/9 5:08 下午
 **/
@RestController
@RequestMapping("/notice/message")
@RequiredArgsConstructor
@Api(tags = {SwaggerTag.CMS + SwaggerTag.NOTICE_DYNAMICS})
@Validated
public class NoticeMessageController {

    private final NoticeMessageService noticeMessageService;

    @SysLog("院务公开列表")
    @GetMapping("list")
    @ApiOperation("院务公开列表")
    @PreAuthorize("@p.check('notice:message:list')")
    @ApiImplicitParam(name = "title", value = "标题", dataType = "string", paramType = "query", required = true)
    public PageVO list(PageParamsVO pageParamsVO, String title){
        return noticeMessageService.list(pageParamsVO, title);
    }

    @SysLog("添加院务公开")
    @PostMapping
    @ApiOperation("添加院务公开")
    @PreAuthorize("@p.check('notice:message:save')")
    public void save(@RequestBody NoticeMessageBO noticeMessageVO){
        noticeMessageService.saveOrUpdate(noticeMessageVO);
    }

    @SysLog("修改院务公开")
    @PutMapping
    @ApiOperation("修改院务公开")
    @PreAuthorize("@p.check('notice:message:update')")
    public void update(@RequestBody NoticeMessageBO noticeMessageVO){
        noticeMessageService.saveOrUpdate(noticeMessageVO);
    }

    @SysLog("删除院务公开")
    @DeleteMapping
    @ApiOperation("删除院务公开")
    @ApiImplicitParam(name = "id", value = "ID", dataType = "long", paramType = "query", required = true)
    @PreAuthorize("@p.check('notice:message:delete')")
    public void delete(@NotNull(message = "id不能为空") Long id){
        noticeMessageService.delete(id);
    }
}
